<template>
  <div class="header">
    <div class="header-menu u-fx-ac u-fx">
      <div class="header-logo"></div>
      <div class="u-fx-f1">
        <ul class="u-fx">
          <li
            :class="{ act: currentIndex === index }"
            v-for="(menu, index) in menuList"
            :key="index"
            @click="goModule(menu.path)"
          >
            {{ menu.name }}
          </li>
        </ul>
      </div>
      <div class="u-fx-ac">
        <img class="user-icon" :src="userInfo.photoUrl || userIcon" alt />
        {{ userInfo.userName || '暂无昵称' }}
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'HeaderTop',
  computed: {
    ...mapState('home', ['userInfo']),
    currentIndex() {
      const index = this.menuList.findIndex(v => v.path === this.$route.path)
      return index > -1 ? index : 0
    }
  },
  data() {
    return {
      menuList: [
        {
          path: '/home',
          name: '首页'
        },
        {
          path: '/classPlan',
          name: '课程安排'
        },
        {
          path: '/classRecord',
          name: '课程记录'
        },
        {
          path: '/personCenter',
          name: '个人中心'
        }
      ]
    }
  },
  methods: {
    goModule(path) {
      this.$router.push(path)
    }
  }
}
</script>

<style lang="less" scoped>
.header {
  width: 100%;
  height: 72px;
  position: fixed;
  z-index: 999;
  top: 0;
  left: 0;
  background-color: #fff;
  box-shadow: 0 1px 3px #eee;
  .header-menu {
    width: 1200px;
    margin: 0 auto;
    ul {
      margin: 0 0 0 40px;
      padding: 0;
    }
    li {
      cursor: pointer;
      width: 100px;
      line-height: 72px;
      text-align: center;
      font-size: 14px;
      &:hover {
        color: @u-type-primary;
      }
      &.act {
        color: @u-type-primary;
      }
    }
  }
  .header-logo {
    width: 100px;
    height: 50px;
    background: @u-bg-color;
  }
  .user-icon {
    width: 42px;
    height: 42px;
    border-radius: 100%;
    background: @u-bg-color;
    display: block;
    margin-right: 10px;
  }
}
</style>
